package com.dongdongmovie.service.impl;

import com.dongdongmovie.mapper.TabRouteMapper;
import com.dongdongmovie.pojo.PageResult;
import com.dongdongmovie.pojo.TabRoute;
import com.dongdongmovie.pojo.TabRouteExample;
import com.dongdongmovie.service.TabRoute_Service;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.apache.dubbo.config.annotation.DubboService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Arrays;
import java.util.Date;
import java.util.List;

@Service
@DubboService
public class TabRoute_ServiceImpl implements TabRoute_Service {

    //注入mapper
    @Autowired
    private TabRouteMapper tabRouteMapper;

    //查询数据
    @Override
    public PageResult<TabRoute> show(TabRoute t, Integer pageNum, Integer pagesize) {
        PageHelper.startPage(pageNum, pagesize);
        List<TabRoute> list = tabRouteMapper.show(t);
        PageInfo pageInfo = new PageInfo(list);
        PageResult<TabRoute> pageResult = new PageResult<>(pageNum,pagesize,pageInfo.getTotal(),pageInfo.getList(),pageInfo.getPages());
        return pageResult;
    }

    //添加数据
    @Override
    public int add(TabRoute t) {
        return tabRouteMapper.insertSelective(t);
    }

    //查询全部
    @Override
    public TabRoute showAll(Integer rid) {
        return tabRouteMapper.selectByPrimaryKey(rid);
    }

    //修改数据
    @Override
    public int updatebyId(TabRoute t) {
        return tabRouteMapper.updateByPrimaryKeySelective(t);
    }

    //根据id删除
    @Override
    public int delete(Integer rid) {
        return tabRouteMapper.deleteByPrimaryKey(rid);
    }

    //删除全部
    @Override
    public int deleteall(Integer[] rids) {
        TabRouteExample te = new TabRouteExample();
        TabRouteExample.Criteria criteria = te.createCriteria();
        criteria.andRidIn(Arrays.asList(rids));
        return tabRouteMapper.deleteByExample(te);
    }

    //上架
    @Override
    public int updateputaway(Integer rid) {
        TabRoute tabRoute = tabRouteMapper.selectByPrimaryKey(rid);
        tabRoute.setRdate(new Date());
        tabRoute.setRflag(1);
        return tabRouteMapper.updateByPrimaryKeySelective(tabRoute);
    }

    @Override
    public int updatesoldout(Integer rid) {
        TabRoute tabRoute = tabRouteMapper.selectByPrimaryKey(rid);
        tabRoute.setRflag(0);
        return tabRouteMapper.updateByPrimaryKeySelective(tabRoute);
    }
}
